package com.his.admin.controller;

import com.his.admin.service.HospitalService;
import com.his.admin.service.OrderService;
import com.his.dao.domain.dto.AllMedicineDto;
import com.his.dao.domain.dto.ListDto;
import com.his.dao.domain.dto.MedicineListDto;
import com.his.dao.domain.entity.Hospital;
import com.his.dao.domain.entity.Order;
import com.his.util.annotation.RequiresLogin;
import com.his.util.annotation.RequiresPermissions;
import com.his.util.result.RestResult;
import com.his.util.result.RestResultBuilder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
@AllArgsConstructor
@Api(value = "订单模块")
public class OrderController {
    private OrderService orderService;

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/all")
    @ApiOperation(value = "获取订单列表",notes = "获取订单列表")
    public RestResult all(@RequestBody ListDto listDto) {
        return orderService.all(listDto);
    }

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/allSave")
    @ApiOperation(value = "存储所有订单列表",notes = "存储所有订单列表")
    public RestResult allSave(@RequestHeader("authorization")String authorization, @RequestBody MedicineListDto medicineListDto) {
        return orderService.allSave(authorization,medicineListDto);
    }

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/add")
    @ApiOperation(value = "增加订单",notes = "增加订单")
    public RestResult add(@RequestBody Order order) {
        if (orderService.save(order)) {
            return new RestResultBuilder().success();
        }
        return new RestResultBuilder().fail();
    }


    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/update")
    @ApiOperation(value = "更新订单",notes = "更新订单")
    public RestResult update(@RequestBody Order order) {
        if (orderService.updateById(order)) {
            return new RestResultBuilder().success();
        }
        return new RestResultBuilder().fail();
    }

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/delete")
    @ApiOperation(value = "删除订单",notes = "删除订单")
    public RestResult delete(@RequestBody List<Integer> ids) {
        if (orderService.removeByIds(ids)) {
            return new RestResultBuilder().success();
        }
        return new RestResultBuilder().fail();
    }

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/determine")
    @ApiOperation(value = "处理订单",notes = "处理订单")
    public RestResult determine(@RequestBody Order orderId) {
        return orderService.determine(orderId);
    }
}